package com.qcby.shujia.demo.interceptor;

import com.qcby.shujia.demo.anno.PreAuth;
import com.qcby.shujia.demo.common.constant.QcbyConstant;
import com.qcby.shujia.demo.entity.User;
import com.qcby.shujia.demo.service.UserService;
import com.qcby.shujia.demo.util.ContextUtil;
import com.qcby.shujia.demo.util.TokenUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @className: LoginInterceptor
 * @description: 登录验证拦截器
 * @author: whz
 * @date: 2021/9/23
 **/
public class LoginInterceptor implements HandlerInterceptor {
    //controller执行前
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String uri=request.getRequestURI();
        System.out.println("您请求的路径是"+uri);
        //获取注解
       // HandlerMethod handlerMethod=(HandlerMethod) handler;
       // RequestMapping requestMapping=handlerMethod.getMethodAnnotation(RequestMapping.class);
        //String token=request.getHeader(QcbyConstant.TOKEN);

//        if(TokenUtil.verToken(token)){
//            System.out.println("登录失败");
//            throw new RuntimeException("登陆失败");
//        }


            //登录验证通过
            System.out.println("登录验证通过");

           // User user=TokenUtil.getUser(token);
            //获取用户权限信息
        //PreAuth preAuth=handlerMethod.getMethodAnnotation(PreAuth.class);
        //System.out.println(preAuth);
       // List<String> authStrList =user.getAuthStrList();
        
        //System.out.println(authStrList);
//        if(!authStrList.contains(preAuth.value())){
//            System.out.println("无权限访问");
//            throw new RuntimeException("无权限访问");
//        }
        return true;

    }
}
